package com.manage.dao;

import com.manage.pojo.User;
import com.manage.util.ApacheUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author 汤奇
 * @version V1.0
 * @Project BookPro
 * @Package com.manage.dao
 * @Description:
 * @Date 2022/5/27 12:47
 */
public class UserDaoImpl implements UserDao {
    private QueryRunner qr = new QueryRunner(ApacheUtil.getDataSource());
    @Override
    public User findUser(String username, String password) {
        String sql = "select * from user where username=? and password=?";
        User user = null;
        try {
            user = qr.query(sql, new BeanHandler<User>(User.class), username, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return user;
    }

    @Override
    public int addOne(String username, String password) {
        String sql = "insert into user(username,password,status) value(?,?,?) ";
        int count = 0;
        try {
            count = qr.update(sql, username, password, 1);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return count;
    }
}
